
public class ThreadingTest implements Runnable
{
	public static volatile int m_semaphore = 0;
	/** this is the main message of the program */
	private String m_message;
	/** how many times to display the message */
	private int m_count;
	
	LinkedList<String> m_list;
	/**
	 * @param a_message
	 * @see #m_message
	 */
	ThreadingTest(String a_message, int a_count, LinkedList<String> a_list)
	{
		m_message = a_message;
		m_count = a_count;
		m_list = a_list;
	}
	public void run()
	{
		LinkedList<String>.LinkedListNode n = null;
		for(int i = 0; i < m_count; ++i)
		{
			synchronized(m_list)
			{
				n = m_list.removeFirst();
				if(n != null)
				{
					String name = n.data;
					m_list.add(name);
				}
			}
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		LinkedList<String> list = new LinkedList<String>();
		list.add("Byork");
		list.add("Tlawton");
		list.add("Brockwell");
		list.add("Malstad");
		list.add("Wbadal");
		list.add("Ereyes");
		list.add("Kpickering");
		list.add("Sflynn");
		list.add("Mweir");
		list.add("Nsmith");
		list.add("Ltello");
		System.out.println("["+list.print()+"]");
		// equivalent to the line above
		//System.out.println(new StringBuffer("[").append(list.print()).append("]"));
		ThreadingTest g = new ThreadingTest("A", 1000, list);
		Thread t = new Thread(g);
		ThreadingTest g2 = new ThreadingTest("B", 1000, list);
		Thread t2 = new Thread(g2);
		t.start();
		t2.start();
		try{Thread.sleep(500);}catch(Exception e){}
		System.out.println("["+list.print()+"]");
	}
}
